this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};this.BX.Landing.UI=this.BX.Landing.UI||{};(function(t,e){"use strict";class i{constructor(t){this.maxHeight=0;this.element=t;i.MIN_SIZE=8;this.startSize=parseInt(e.Dom.style(t,"font-size"));this.currentSize=this.startSize;this.letterSpacingRatio=e.Dom.style(t,"letter-spacing");this.letterSpacingRatio=parseFloat(this.letterSpacingRatio)||0;this.letterSpacingRatio/=this.startSize;this.currentLetterSpacing=i.MIN_LETTER_SPACING;this.startLineHeight=parseFloat(e.Dom.style(t,"line-height"));this.startLineHeight=e.Type.isNumber(this.startLineHeight)?(this.startLineHeight/this.startSize).toFixed(1):i.MIN_LINE_HEIGHT;this.currentLineHeight=this.startLineHeight;this.prevWidth=this.element.clientWidth;this.calcMaxHeight()}calcMaxHeight(){this.maxHeight=document.documentElement.clientHeight*.9;if(this.element.offsetParent){this.maxHeight=Math.min(this.maxHeight,this.element.offsetParent.clientHeight)}}resetSize(){this.element.style.setProperty("font-size",null);this.element.style.setProperty("letter-spacing",null);this.element.style.setProperty("line-height",null);this.currentSize=this.startSize;this.currentLineHeight=this.startLineHeight;this.currentLetterSpacing=this.letterSpacingRatio*this.startSize}adjust(){this.calcMaxHeight();if(this.isNeedDecrease()){this.decreaseSize()}else if(this.isNeedIncrease()){this.increaseSize()}}isNeedDecrease(){return(this.element.scrollWidth>this.element.clientWidth||this.element.offsetHeight>this.maxHeight)&&this.currentSize>i.MIN_SIZE}decreaseSize(){let t=this.currentSize-this.currentSize*i.STEP_SIZE_PERCENTS/100;t=Math.floor(t);t=Math.max(i.MIN_SIZE,t);if(this.currentSize!==t){if(!this.intervalId){this.intervalId=setInterval((()=>{if(this.isNeedDecrease()){this.decreaseSize()}else{this.finishAdjust()}}))}this.setFontSize(t)}}isNeedIncrease(){return!this.isNeedDecrease()&&this.element.clientWidth>this.prevWidth&&this.element.clientWidth-this.prevWidth>this.element.clientWidth*i&&this.currentSize<this.startSize}increaseSize(){let t=this.currentSize+this.currentSize*i.STEP_SIZE_PERCENTS/(100-i.STEP_SIZE_PERCENTS);t=Math.ceil(t);t=Math.min(this.startSize,t);if(this.currentSize!==t){if(!this.intervalId){this.intervalId=setInterval((()=>{if(this.isNeedIncrease()){this.increaseSize()}else if(this.isNeedDecrease()){this.decreaseSize();this.finishAdjust()}else{this.finishAdjust()}}))}this.setFontSize(t)}}finishAdjust(){clearInterval(this.intervalId);this.intervalId=null;this.prevWidth=this.element.clientWidth}setFontSize(t){if(t!==this.currentSize&&t<=this.startSize){this.currentSize=t;this.element.style.setProperty("font-size",this.currentSize+"px","important");if(this.startLineHeight>i.MIN_LINE_HEIGHT){let e=i.MIN_LINE_HEIGHT+(this.startLineHeight-i.MIN_LINE_HEIGHT)*t/this.startSize;e=e.toFixed(1);e=Math.max(e,i.MIN_LINE_HEIGHT);if(e<=this.startLineHeight&&e!==this.currentLineHeight){this.element.style.setProperty("line-height",e,"important");this.currentLineHeight=e}}if(this.letterSpacingRatio>i.MIN_LETTER_SPACING){let e=this.letterSpacingRatio*t;e=Math.round(e);if(e!==this.currentLetterSpacing){this.element.style.setProperty("letter-spacing",e+"px","important");this.currentLetterSpacing=e}}}}}i.STEP_SIZE_PERCENTS=10;i.MIN_SIZE=12;i.MIN_LINE_HEIGHT=1.4;i.MIN_LETTER_SPACING=0;const s=BX.Landing.Utils.bind;const n=BX.Landing.Utils.slice;const h=BX.Landing.Utils.onCustomEvent;let r=BX.width(window);class a{static isNeedAdjust(){return BX.width(window)<=a.WIDTH_LIMIT}static isResized(){const t=r!==BX.width(window);r=BX.width(window);return t}constructor(t){this.entries=t.map(this.createEntry,this);this.onResize=e.Runtime.debounce(this.onResize,500);s(window,"resize",this.onResize.bind(this,false));s(window,"orientationchange",this.onResize.bind(this,true));h("BX.Landing.Block:init",this.onAddBlock.bind(this));this.adjust(true)}onResize(t){this.adjust(t)}adjust(t){if(t===true||a.isResized()){const t=a.isNeedAdjust();this.entries.forEach((e=>{if(t){e.adjust()}else{e.resetSize()}}))}}createEntry(t){return new i(t)}addElements(t){t.forEach((t=>{const e=this.entries.some((e=>e.element===t));if(!e){this.entries.push(this.createEntry(t))}}),this)}onAddBlock(t){const e=n(t.block.querySelectorAll("h1, h2, h3, h4, h5, [data-auto-font-scale]"));this.addElements(e)}}a.WIDTH_LIMIT=768;t.AutoFontScale=a})(this.BX.Landing.UI.Tool=this.BX.Landing.UI.Tool||{},BX);
//# sourceMappingURL=auto_font_scale.bundle.map.js